//
//  RouteError.swift
//  XBasicKit
//
//  Created by x on 2024/8/31.
//

// MARK: - 路由错误类型定义

public enum RouteError: LocalizedError {
    case invalidNavigationController(for: AppRoute)
    case cannotPresent(from: AppRoute)
    case cannotDetail(from: AppRoute)
    case cannotCustomModal(from: AppRoute)
    case unsupportedRoute(AppRoute)
    case invalidParamsKey(from: UIViewController, key: String, value: Any)
    case invalidURL(URL: URLConvertible)
    case navigationBlocked(by: RouteInterceptor)
    case invalidWindow(AppRoute)
    case customError(AppRoute, message: String)

    public var errorDescription: String? {
        switch self {
        case .invalidNavigationController(let route):
            return "Invalid navigation controller for route: \(route). Ensure that a valid UINavigationController is provided."
        case .cannotPresent(let route):
            return "Cannot present route: \(route). The navigation controller is nil or presentation is not possible."
        case .cannotDetail(let route):
            return "Cannot showDetailController route: \(route). The navigation controller is nil or show detail is not possible."
        case .cannotCustomModal(let route):
            return "Cannot custom Modal route: \(route). The navigation controller is nil or Modal is not possible."
        case .unsupportedRoute(let route):
            return "Unsupported route: \(route). This route is not handled in the current configuration."
        case .invalidWindow(let route):
            return "Invalid window: \(route)"
        case .invalidURL(let url):
            return "Invalid URL: \(url). Unable to parse or map to a valid route."
        case .navigationBlocked(by: let interceptor):
            return "Navigation blocked by interceptor: \(interceptor)."
        case .customError(let route, let message):
            return "Navigation failed for route: \(route) with message: \(message)"
        case .invalidParamsKey(from: let vc, key: let key, value: let value):
            return "Invalid key:\(key) --> value\(value) from \(vc)"
        }
    }
}

